
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 3
 * @Author : WangRuoyu 
 * @Date : 2023/5/14 14:56
 */

#include "iostream"
#include "algorithm"

using namespace std;

struct soldier {
    int attack;
    int health;
    int nums;
} d[2][8];


void addSoldier(int player, int pos, int h, int a) {
    d[player][0].nums++;
    for (int i = d[player][0].nums - 1; i >= pos; --i) {
        d[player][i + 1] = d[player][i];
    }
    d[player][pos].health = h;
    d[player][pos].attack = a;
}

void removeSoldier(int player, int posa) {
    for (int i = posa; i < d[player][0].nums; ++i) {
        d[player][i] = d[player][i + 1];
    }
    d[player][d[player][0].nums] = {0, 0, 0};
    d[player][0].nums--;
}

int main() {
    int n;
    d[0][0].attack = 0;
    d[1][0].attack = 0;
    d[0][0].health = 30;
    d[1][0].health = 30;
    cin >> n;
    int player = 0;
    int winner = 0;

    while (n--) {
        string str;
        cin >> str;
        if (str == "end") player = 1 - player;
        else if (str == "summon") {
            int pos, h, a;
            cin >> pos >> a >> h;
            addSoldier(player, pos, h, a);
        } else {
            int posa, posb;
            cin >> posa >> posb;
            d[player][posa].health -= d[1 - player][posb].attack;
            d[1 - player][posb].health -= d[player][posa].attack;
            if (d[player][posa].health <= 0) {
                if (posa == 0) {
                    winner = (1 - player) == 0 ? 1 : -1;
                    break;
                } else removeSoldier(player, posa);
            }
            if (d[1 - player][posb].health <= 0) {
                if (posb == 0) {
                    winner = player == 0 ? 1 : -1;
                    break;
                } else removeSoldier(1 - player, posb);
            }
        }
    }
    cout << winner << endl;
    cout << d[0][0].health << endl;
    cout << d[0][0].nums;
    for (int i = 1; i <= d[0][0].nums; ++i) {
        cout << " " << d[0][i].health;
    }
    cout<<endl;
    cout << d[1][0].health << endl;
    cout << d[1][0].nums;
    for (int i = 1; i <= d[1][0].nums; ++i) {
        cout << " " << d[1][i].health;
    }
    return 0;
}